home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / _fstat.c < prev    next >
C/C++ Source or Header  |  1994-04-04  |  2KB  |  71 lines

  1. RCS_ID_C="$Id: _fstat.c,v 3.2 1994/04/04 01:36:59 jraja Exp $";
  2. /*
  3.  * _fstat.c --- fstat() for Network Support Library
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * This file is part of the AmiTCP/IP Network Support Library.
  8.  *
  9.  * Copyright © 1993,1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  10.  *             Helsinki University of Technology, Finland.
  11.  *             All rights reserved.
  12.  *
  13.  * Created      : Sun Mar 27 19:58:21 1994 ppessi
  14.  * Last modified: Sun Mar 27 20:34:49 1994 ppessi
  15.  */
  16.  
  17. #include <sys/types.h>
  18. #include <sys/socket.h>
  19. #include <sys/stat.h>
  20. #include <errno.h>
  21.  
  22. #include <string.h>
  23. #include <stdlib.h>
  24.  
  25. /* DOS 3.0 and MuFS extensions to file info block */
  26. #include "fibex.h"
  27. #include <proto/dos.h>
  28. #include <proto/utility.h>
  29.  
  30. #include <ios1.h>
  31.  
  32. int fstat(int fd, struct stat *st)
  33. {
  34.   struct UFB *ufb = chkufb(fd);
  35.  
  36.   if (st == NULL || ((1 & (long)st) == 1)) {
  37.     errno = EFAULT;
  38.     return -1;
  39.   }
  40.  
  41.   if (ufb == NULL || ufb->ufbflg == 0) {
  42.     errno = EBADF;
  43.     return -1;
  44.   }
  45.  
  46.   if (ufb->ufbflg & UFB_SOCK) { /* a socket */
  47.     long value;
  48.     long size = sizeof(value);
  49.     bzero(st, sizeof(*st));
  50.  
  51.     /* st->st_dev = ??? */
  52.     st->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
  53.     st->st_uid = geteuid();
  54.     st->st_gid = getegid();
  55.  
  56.     if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &size) == 0)
  57.       st->st_blksize = value;
  58.  
  59.     return 0;
  60.   } else { /* ordinal file */
  61.     if (ExamineFH(ufb->ufbfh, __dostat_fib)) {
  62.       __dostat(__dostat_fib, st);
  63.       st->st_dev = (dev_t)((struct FileHandle *)BADDR(ufb->ufbfh))->fh_Type;
  64.       return 0;
  65.     } else {
  66.       errno = EIO;
  67.       return -1;
  68.     }
  69.   }
  70. }
  71.